package com.design.pattern.mediator;

/**
 * 具体的交易平台
 */
public class ConcreteIntermediary implements Intermediary {
    private DishBoss dishBoss;
    private MeterBoss meterBoss;
    private MeatBoss meatBoss;
    private GreaseBoss greaseBoss;

    public ConcreteIntermediary(DishBoss dishBoss, MeterBoss meterBoss, MeatBoss meatBoss, GreaseBoss greaseBoss) {
        this.dishBoss = dishBoss;
        this.meterBoss = meterBoss;
        this.meatBoss = meatBoss;
        this.greaseBoss = greaseBoss;
    }

    @Override
    public String buyMeter(Money money) {

        return meterBoss.shell(money);
    }

    @Override
    public String buyDish(Money money) {
        return dishBoss.shell(money);
    }

    @Override
    public String buyGrease(Money money) {
        return greaseBoss.shell(money);
    }

    @Override
    public String buyMeat(Money money) {
        money=money instanceof JiaoZi?money:changeMoney(money);
        return meatBoss.shell(money).replace("生肉","卤肉");
    }

    /**
     * 货币兑换
     * @param money
     * @return
     */
    public static Money changeMoney(Money money){

        if (money instanceof Silver){
            JiaoZi jiaozi=new JiaoZi();
            jiaozi.setNumber(money.getNumber());
            return jiaozi;
        }else {
            Silver silver=new Silver();
            silver.setNumber(money.getNumber());
            return silver;
        }
    }
}
